<cfset mySelf = viewState.getValue("mySelf") />
<cfset resourceUrl = viewstate.getValue("resourceUrl") />
<cfset resourceFolder = listDeleteAt(resourceUrl,listLen(resourceUrl,"/"),"/") />
<cfset repoResource = viewstate.getValue("repoResource") />
<cfset currentUser = viewstate.getValue("currentUser") />
<cfset commitEvent = viewstate.getValue("myself") & viewstate.getValue("xe.commit") />
<cfset extra.javascript = viewstate.getValue("extra.javascript") />
<cfset extra.fckconfig = viewstate.getValue("extra.fckconfig") />

<cfset request.modelGlueSuppressDebugging = true />

	<cffunction name="safeString" returntype="string" output="false">
		<cfargument name="stringToClean" required="true" type="string">
		<cfreturn rereplacenocase(stringToClean,'[^a-z|A-Z|0-9|_]','','all')>
	</cffunction>

<!---
 <cfset isNew = true />
<cfif (not isNumeric(page.pageId) and len(page.pageId)) or (isNumeric(page.pageId) and page.pageId)>
	<cfset isNew = false />
</cfif>
 --->
<cfset baseURL = replace("/" & listDeleteAt(cgi.script_name,listLen(cgi.script_name,"/"),"/")& "/","//","/","all") >
<cfhtmlhead text='<script type="text/javascript" src="/srvinc/fckeditor/fckeditor.js"></script>'>
<script>
var scriptScope = this;
if(typeof _container_ == 'undefined'){
    var _container_ = dojo;
}

function allInputValid(f) {
	var s = '';
	var canSubmit = true;
  var inValidMsg = '';
  var hasReqMsg = '';
	for (var i = 0; i < f.elements.length; i++) {
	    var elem = f.elements[i];
	    aDojoWidget = dojo.widget.byId(elem.name);
	    if (aDojoWidget && typeof aDojoWidget.isMissing != 'undefined') {
	    if (aDojoWidget.isMissing()) {
	        aDojoWidget.updateClass('Invalid');
          canSubmit = false;
					hasReqMsg = 'Please correct the fields marked as required';
      }
	    if (!aDojoWidget.isValid()) {
	        aDojoWidget.updateClass('Invalid');
          canSubmit = false;
					inValidMsg = '\nPlease correct the fields marked as invalid';
	    }
    }
	}
	if(!canSubmit) alert(hasReqMsg+inValidMsg);
	return canSubmit;
}

		this.submitForm = function() {
			var formNode = dojo.byId('pageForm');
			dojo.byId('commitMessage').value = dojo.byId('commitMessageF').value;
			if (allInputValid(formNode)) {
			  var oEditor = FCKeditorAPI.GetInstance( 'content' ) ;
			  oEditor.UpdateLinkedField();
			  dojo.io.bind ({
			    url: '<cfoutput>/#commitEvent#&resourceUrl=#listFirst(resourceUrl,":")#</cfoutput>',
			    handler: oEditor.Commands.GetCommand('svnAutoSave').succIcon,
					// changeUrl: 'form',
					//mimetype: 'text/html',
			    formNode: formNode
			  });
			}
    }

    function retFormData(type,data,evt) {
    	whyDoIhaveTo = data;
    	updateDivContent(type,whyDoIhaveTo,evt);
    }

		function commitNow(retFunk) {
		  scriptScope.commitDialog.show(retFunk);		  
		}

this.fckEd = {
	init: function() {
		scriptScope.fckEditor = new FCKeditor( 'content' ) ;
		scriptScope.fckEditor.BasePath	= '/srvinc/fckeditor/' ;
		scriptScope.fckEditor.Config['AjaxSaveUrl']='<cfoutput>/#commitEvent#</cfoutput>';
		scriptScope.fckEditor.Config['svnAutoSaveTargetUrl']='<cfoutput>/#commitEvent#&resourceUrl=#listFirst(resourceUrl,":")#</cfoutput>';
		<!--- scriptScope.fckEditor.Config['CustomConfigurationsPath'] = '<cfoutput>#baseurl##myself#</cfoutput>public.fckConfig'; --->
		scriptScope.fckEditor.ToolbarSet = 'svnpage';
		scriptScope.fckEditor.Config["PageTitle"]	= '<cfoutput>#repoResource.name#</cfoutput>' ;
		scriptScope.fckEditor.Width			= "100%";
		scriptScope.fckEditor.Height		= 500;
		scriptScope.fckEditor.Config["BaseHref"] = "/";
		scriptScope.fckEditor.Config["MaxLength"] = 10;
		//fckEditor.Config['CounterName'] = 'text_1_cnt';
		scriptScope.fckEditor.Config["Debug"] = false;
		<cfif viewstate.getValue("fullpage") gt "">
			scriptScope.fckEditor.Config["FullPage"] = true;
		</cfif>
<cfoutput>
	#extra.fckconfig#
	scriptScope.fckEditor.Config["ImageBrowser"] = true;
	scriptScope.fckEditor.Config["ImageBrowserURL"] = '/srvinc/fckplugins/connector/filemanager/browser/svn/browser.html?Type=Image&CurrentFolder=#resourceFolder#/images/&Connector=/?event=repo.fckConnector' ;
	scriptScope.fckEditor.Config["LinkBrowser"] = true;
	scriptScope.fckEditor.Config["LinkBrowserURL"] = '/srvinc/fckplugins/connector/filemanager/browser/svn/browser.html?Connector=/?event=repo.fckConnector&CurrentFolder=#resourceFolder#' ;
</cfoutput>
		//fckEditor.config["LinkBrowserWindowWidth"] = 'screen.width * 0.7'; // 70% 
		//fckEditor.config["LinkBrowserWindowHeight"] = 'screen.height * 0.7'; // 70% 
		scriptScope.fckEditor.Config["SkinPath"] = '/srvinc/fckplugins/skins/SilverNarrow/' ;
		scriptScope.fckEditor.Config["FontNames"]	= 'Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana;' ;
		//scriptScope.fckEditor.Config["EditorAreaCSS"] = '/pages/css/nmkids.css' ;
		scriptScope.fckEditor.Config["ToolbarCanCollapse"] = true;
		scriptScope.fckEditor.Config['CustomConfigurationsPath'] = '<cfoutput>/#myself#</cfoutput>repo.resource.edit.fckConfig';
		//fckEditor.Create();
		scriptScope.fckEditor.ReplaceTextarea() ;
		
		//any additional JS
	},
	setEd : function(ed) {scriptScope.editor = ed;}
}


<cfoutput>#extra.javascript#</cfoutput>

this.fckEditor = '';

this.modalPop = {
		init: function () {
			dlgProg = dojo.widget.createWidget("dojo:Dialog",{toggle:"fade",toggleDuration:250}, dojo.byId("dialogNode"));
			dojo.byId('commitIt').onclick = commitNow;
			dojo.byId('hidecommit').onclick = scriptScope.modalPop.hide;
			dojo.byId('retMessage').onclick = scriptScope.commitDialog.showmsg;
			
			
			//var btn2 = document.getElementById("hider2");
			//dlgProg.setCloseControl(btn2);
		},
		show: function() {
		  dlgProg.show();
		},
		setContent: function(content) {
		  dojo.byId('dialogNodeText').innerHTML = (content);
		},
		hide: function(content) {
		  dlgProg.hide();
		}
}

this.commitDialog = {
		show: function (retFunk) {
//			scriptScope.modalPop.setContent('Commit Message<br /><textarea name="commitMessage" cols="40" rows="7"></textarea>');
			scriptScope.modalPop.show();
			dojo.byId('retFunker').onclick = retFunk;
		},
		commit: function () {
			scriptScope.modalPop.hide();
		},
		showmsg: function (msg) {
			scriptScope.modalPop.setContent(msg);
		}
}


dojo.addOnLoad(this.fckEd.init);
_container_.addOnLoad(scriptScope.modalPop.init);
</script>


<!---
<cfoutput>	
	<div dojoType="PopupMenu2" widgetId="submenu1" contextMenuForWindow="false" targetNodeIds="mainPane">
		<div dojoType="MenuItem2" caption="Edit Content" onClick="setMainPane('#myself#page.view&pageID=#page.pageID#&edit=1');"></div>
		<div dojoType="MenuItem2" caption="View Content" disabled="true" onclick="setMainPane('#myself#page.view&pageID=#page.pageID#');"></div>
	</div>
</cfoutput>
 --->
<style type="text/css">
.dojoDialog {
	background : #eee;
	border : 2px solid #999;
	-moz-border-radius : 5px;
	padding : 15px;
	text-align:left;
}

form {
	margin-bottom : 0;
}
</style>


<form action="<cfoutput>#myself##commitEvent#</cfoutput>" method="post" class="edit" name="pageForm" id="pageForm">

<cfoutput>
	<textarea name="content" id="content"><cfoutput>#toString(repoResource.content)#</cfoutput></textarea>
	<input type="button" id="svncommit" onclick="scriptScope.commitDialog.show(retFormData)" style="display:none;">
	<input type="button" id="hidecommit" style="display:none;">
	<input type="button" id="retMessage" style="display:none;">
	<input type="button" id="commitIt" style="display:none;">
	<input type="button" id="retFunker" style="display:none;">

	<input type="hidden" name="userID" value="#currentUser.getRecord().getUserId()#">
	<input type="hidden" name="moduserID" value="#currentUser.getRecord().getUserId()#">
	<input type="hidden" name="projectId" value="1">
	<input type="hidden" name="commitMessage" id="commitMessage" value="">
	<input type="hidden" name="createdate" value="#createODBCdateTime(now())#">
	<input type="hidden" name="moddate" value="#createODBCdateTime(now())#">
	<input type="hidden" name="pageText" id="pageText" value="">
</cfoutput>
	<input type="hidden" id="weet" onclick="scriptScope.savePage()">
<!--- replace(replace(page.pageText,"'","\'","all"),chr(13)&chr(10),"","all") --->
<!---
<cfoutput>
	<button dojoType="Button" id="savePageButton" name="savePageButton" onclick="scriptScope.savePage()">
		<span style="font-size:1.1em; font-weight:bold;">Save This Page</span>
	</button>
</cfoutput>
 --->
<!---
 
			<cfscript>
				fckEditor = createObject("component", "/srvinc/fckeditor/fckeditor");
				fckEditor.instanceName	= "pageText";
	      fckEditor.config["PageTitle"]	= '#page.pageName#' ;
				fckEditor.value			= '#page.pageText#';
				fckEditor.basePath		= "/srvinc/fckeditor/";
				fckEditor.width			= "100%";
				fckEditor.height		= 500;
				fckEditor.config["CustomConfigurationsPath"] = '/go/?to=fckConfig';
				//fckEditor.config["CustomConfigurationsPath"] = '/go/jsFckConfig.cfm';
				fckEditor.config["BaseHref"] = "http://#cgi.host_name#/";
				fckEditor.config["Debug"] = true;
//				fckEditor.config["LinkBrowser"] = true ;
//				fckEditor.config["LinkBrowserURL"] = "/srvinc/fckplugins/connector/filemanager/browser/default/browser.html?Connector=/srvinc/fckplugins/connector/connectorDB.cfm" ;
//				fckEditor.config["ImageBrowser"] = true ;
//				fckEditor.config["ImageBrowserURL"] = '/srvinc/fckplugins/connector/filemanager/browser/default/browser.html?Type=Image&Connector=/srvinc/fckplugins/connector/connectorDB.cfm' ;
				//fckEditor.config["LinkBrowserWindowWidth"] = 'screen.width * 0.7'; // 70% 
				//fckEditor.config["LinkBrowserWindowHeight"] = 'screen.height * 0.7'; // 70% 
				//fckEditor.config["LinkBrowserURL"] = fckEditor["basePath"] & 'editor/filemanager/browser/default/browser.html?Connector=connectors/php/connector.php' ;
				//fckEditor.config["ImageBrowserURL"] = fckEditor["basePath"] & 'editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/php/connector.php' ;
				//fckEditor.config["LinkBrowserURL"] = fckEditor["basePath"] & 'editor/filemanager/browser/fbxp/browser.html?Connector=connectors/php/connector.php' ;
				//fckEditor.config["ImageBrowserURL"] = fckEditor["basePath"] & 'editor/filemanager/browser/fbxp/browser.html?Type=Image&Connector=connectors/php/connector.php' ;
				fckEditor.config["SkinPath"] = fckEditor["basePath"] & 'editor/skins/office2003/' ;
	      fckEditor.config["FontNames"]	= 'Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana;' ;
				//fckEditor.config["EditorAreaCSS"] = '/PreK/include/prek.css' ;
				fckEditor.config["EditorAreaCSS"] = '/css/Osher1.css' ;
				fckEditor.toolBarSet = 'dpages';
				fckEditor.config["ToolbarCanCollapse"] = false;
				fckEditor.create(); // create the editor.
			</cfscript>
	<cfoutput>
		<input type="hidden" id="cfid" value="#session.cfid#">
		<input type="hidden" id="cftoken" value="#session.cftoken#">
		<input type="hidden" id="pageID" name="pageID" value="#val(page.pageId)#">
		<input type="hidden" id="thisID" name="thisID" value="#val(page.pageId)#">
	<div class="controls">
	 	<input type="submit" value="Save" />
	</div>
	</cfoutput>
 --->

<div id="dialogNode" style="display:none;">
	<input type="button" onclick="scriptScope.modalPop.hide();" value="X" style="background:transparent;position:absolute;top:0;right:0;border:0px;" />
		<div id="dialogNodeText">
			Log Message<br /><textarea name="commitMessageF" id="commitMessageF" cols="40" rows="7"></textarea>
		</div>
		<div dojoType="button" id="commitButton" onclick="scriptScope.submitForm()">
			SAVE
		</div>		
		<div dojoType="button" id="cancelButton" onclick="scriptScope.modalPop.hide();">
			CANCEL
		</div>
</div>

</form>